# Add simple GUI for iOS security intrusion_Cordova/Ionic
The AppSealing library within your App is automatically activated when right after App has launched. If AppSealing library has detected any abnormal environment (such as jailbroken-device, executable has decrypted or debugger has attached) it will close the app after 20 seconds irrespectively of user action, so the app should notify the detection result to user and show some proper message box for user can recognize there's some invalid environment in his/her device.
If you want to show that dialog box in your app, you can easily do that inserting small chunk of code into "ViewController.swift" file. (ViewController.mm (opens new window) in case of Objective-C based project)
# Show UIAlertController window in your app
First, open your Xcode project and open ViewController.swift" file.
After you opened the swift file put following code into that (If ViewController.swift file has already included 'viewDidAppear' method just insert the body of following code below 'super.viewDidAppear( animated );' line.)
# Simple UI code into ‘ViewController.swift’ for Swift project
override func viewDidAppear(_ animated: Bool)
{
super.viewDidAppear( animated );
let inst: AppSealingInterface = AppSealingInterface();
let tamper: Int32 = inst._IsAbnormalEnvironmentDetected();
if ( tamper > 0 )
{
var msg = "Abnormal Environment Detected !!";
if ( tamper & DETECTED_JAILBROKEN ) > 0
{ msg += "\n - Jailbroken"; }
if ( tamper & DETECTED_DRM_DECRYPTED ) > 0
{ msg += "\n - Executable is not encrypted"; }
if ( tamper & DETECTED_DEBUG_ATTACHED ) > 0
{ msg += "\n - App is debugged"; }
if ( tamper & ( DETECTED_HASH_INFO_CORRUPTED | DETECTED_HASH_MODIFIED )) > 0
{ msg += "\n - App integrity corrupted"; }
if ( tamper & ( DETECTED_CODESIGN_CORRUPTED | DETECTED_EXECUTABLE_CORRUPTED )) > 0
{ msg += "\n - App executable has corrupted"; }
if ( tamper & DETECTED_CERTIFICATE_CHANGED ) > 0
{ msg += "\n - App has re-signed"; }
let alertController = UIAlertController(title: "AppSealing",
message: msg, preferredStyle: .alert );
alertController.addAction(UIAlertAction(title: "Confirm", style: .default,
handler: { (action:UIAlertAction!) -> Void in
#if !DEBUG // Debug mode does not kill app even if security threat has found
exit(0);
#endif
} ));
self.present(alertController, animated: true, completion: nil);
}
}
Sample UI code above is also included in "AppSealingiOS.mm" file so you can copy & paste int that file.
If your project is Objective-C based then you can use following code to show simple UI.
# Simple UI code into ‘ViewController.mm (opens new window)’ for Objective-C project
#include "AppsealingiOS.h"
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
int tamper = ObjC_IsAbnormalEnvironmentDetected();
if ( tamper > 0 )
{
NSString* msg = @"Abnormal Environment Detected !!";
if (( tamper & DETECTED_JAILBROKEN ) > 0 )
msg = [msg stringByAppendingString:@"\n - Jailbroken"];
if (( tamper & DETECTED_DRM_DECRYPTED ) > 0 )
msg = [msg stringByAppendingString:@"\n - Executable is not encrypted"];
if (( tamper & DETECTED_DEBUG_ATTACHED ) > 0 )
msg = [msg stringByAppendingString:@"\n - App is debugged"];
if ( tamper & ( DETECTED_HASH_INFO_CORRUPTED | DETECTED_HASH_MODIFIED )) > 0
msg = [msg stringByAppendingString:@"\n - App integrity corrupted"];
if ( tamper & ( DETECTED_CODESIGN_CORRUPTED | DETECTED_EXECUTABLE_CORRUPTED )) > 0
msg = [msg stringByAppendingString:@"\n - App executable has corrupted"];
if ( tamper & DETECTED_CERTIFICATE_CHANGED ) > 0
msg = [msg stringByAppendingString:@"\n - App has re-signed"];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"AppSealing"
message:msg
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"Confirm"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
#if !DEBUG && !defined(DEBUG) // Debug mode does not kill app even if security threat has found
exit(0);
#endif
}];
[alert addAction:confirm];
[self presentViewController:alert animated:YES completion:nil];
}
}
Your app will show simple alert box like below when you run your app on abnormal device such as jailbroken or debug your app using Xcode or gdb. In such situation irrespective of user action the app will exit after 20 seconds automatically.
If your project is Cordova based, you can put this code block into MainViewController.mm (opens new window) instead of ViewController.mm (opens new window)
(MainViewController.m file must have the extension changed to .mm)
If your project is Ionic based, the ViewController.swift file is not created, so you can create the GUI by adding the following modified code to AppDelegate.swift file
.
# Simple UI code into ‘AppDelegate.swift’ for Ionic project
func application(_ application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
// Override point for customization after application launch.
let inst: AppSealingInterface = AppSealingInterface();
let tamper: Int32 = inst._IsAbnormalEnvironmentDetected();
if ( tamper > 0 )
{
var msg = "Abnormal Environment Detected !!";
if ( tamper & DETECTED_JAILBROKEN ) > 0
{ msg += "\n - Jailbroken"; }
if ( tamper & DETECTED_DRM_DECRYPTED ) > 0
{ msg += "\n - Executable is not encrypted"; }
if ( tamper & DETECTED_DEBUG_ATTACHED ) > 0
{ msg += "\n - App is debugged"; }
if ( tamper & ( DETECTED_HASH_INFO_CORRUPTED | DETECTED_HASH_MODIFIED )) > 0
{ msg += "\n - App integrity corrupted"; }
if ( tamper & ( DETECTED_CODESIGN_CORRUPTED | DETECTED_EXECUTABLE_CORRUPTED )) > 0
{ msg += "\n - App executable has corrupted"; }
if ( tamper & DETECTED_CERTIFICATE_CHANGED ) > 0
{ msg += "\n - App has re-signed"; }
let alertController = UIAlertController(title: "AppSealing",
message: msg, preferredStyle: .alert );
alertController.addAction(UIAlertAction(title: "Confirm", style: .default,
handler: { (action:UIAlertAction!) -> Void in
#if !DEBUG // Debug mode does not kill app even if security threat has found
exit(0);
#endif
} ));
// show alert
let alertWindow = UIWindow( frame: UIScreen.main.bounds )
alertWindow.rootViewController = UIViewController()
alertWindow.windowLevel = UIWindow.Level.alert + 1;
alertWindow.makeKeyAndVisible()
alertWindow.rootViewController?.present( alertController,
animated: true, completion: nil )
}
return true;
}